//创建一个store
import {combineReducers, configureStore} from "@reduxjs/toolkit";
import {userReducer} from "./userSlice";
import {articleReducer} from "./frontDesk/articleSlice";
import {courseReducer} from "./frontDesk/courseSlice";
import {persistReducer, persistStore} from "redux-persist";
import storage from "redux-persist/lib/storage"
import {commentReducer} from "./frontDesk/commentSlice";
import {activityReducer} from "./frontDesk/activitySlice";
import {adminLoginReducer} from "./backStage/adminLoginSlice";


const persistConfig = {
    key: "root",
    storage,
}

// 持久化处理
const persistedReducer = persistReducer(
    persistConfig,
    combineReducers({
        user: userReducer,
        article: articleReducer,
        adminLogin: adminLoginReducer
    })
)


export const store = configureStore({
    reducer: {
        persistedReducer,
        course: courseReducer,
        comment: commentReducer,
        activity: activityReducer,
    },
    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
            serializableCheck: false,
        }),
})

export const persistor = persistStore(store)